package com.yidu.InventoryManagement.service.impl;

import com.yidu.InventoryManagement.entity.TAStock;
import com.yidu.InventoryManagement.mapper.TAStockMapper;
import com.yidu.InventoryManagement.service.TAStockService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/9
 * &@version 1.0
 */
@Service
public class TaShockServiceImpl implements TAStockService {
    @Resource
    public TAStockMapper taStockMapper;

    /**
     * 分页模糊查ta库存
     * @param map
     * @return
     */
    @Override
    public List<TAStock> selectTAStockk(String date, int page, int limit) {
        Map<String,Object> map=new HashMap<>();
        map.put("date",'%'+date+'%');
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return taStockMapper.selectTAStockk(map);
    }

    /**
     * 分页查行数
     * @param date
     * @return
     */
    @Override
    public int selectTAStockCount(String date) {
        return taStockMapper.selectTAStockCount(date);
    }

    /**
     * 查询TA库存id是否为空
     * @return
     */
    @Override
    public int selectSecurityAccrualStockIdd() {
        return taStockMapper.selectSecurityAccrualStockIdd();
    }


    /**
     * 批量删除
     * @return
     */
    @Override
    public int deleteTaShockk(String securityAccrualStockId) {

        //将id转为数据
        String[] split = securityAccrualStockId.split(",");
        //创建存放id的集合
        ArrayList<Object> equityDataIdList = new ArrayList<Object>();
        for (String id : split) {
            //将id存入集合
            equityDataIdList.add(id);
        }
        return taStockMapper.deleteTaShockk(equityDataIdList);
    }


    /**
     * 添加
     * @param taStock ta库存对象
     * @return
     */
    @Override
    public int insertTaShockk(TAStock taStock) {
        return taStockMapper.insertTaShockk(taStock);
    }


    /**
     * 查询ta库存id最大值
     * @return
     */
    @Override
    public String selectDaId() {
        return taStockMapper.selectDaId();
    }

    /**
     * TA库存修改
     * @param taStock
     * @return
     */
    @Override
    public int updateTAStockk(TAStock taStock) {
        return taStockMapper.updateTAStockk(taStock);
    }



    //////////
    /**
     * 根据时间获取ta库存的总数量
     *
     * @param taStock ta库存对象
     * @return double ta库存总数量
     * @author 任俊杰
     */
    @Override
    public double getTaTotalQuantityByTime(TAStock taStock) {
        return taStockMapper.getTaTotalQuantityByTime(taStock);
    }
}



